<?php
/**
 * 
 */
class ParamSirt extends AppModel {
  
	var $name = 'ParamSirt';
  
  var $displayField = 'id';
  
  
  // beforeDelete() sets this so that afterDelete() can delete the 'base' table record corresponding
  //  to the 'connector' (child) table record.  Can't delete the 'connector' record in beforeDelete()
  //  because of a foreign key constraint in the database (can't delete the parent row when the 
  //  child row's foreign key references that parent row).
  var $justDeletedRecordArray;
  
  
  

  var $validate = array(

	);
  
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'ParamSirtBasis' => array(
			'className' => 'ParamSirtBasis',
			'foreignKey' => 'param_sirt_base_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'JobVersion' => array(
			'className' => 'JobVersion',
			'foreignKey' => 'job_version_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
  
  
  
  
  
  /**
   * Gets called by Cake automatically when a record of this model gets deleted. Here we need
   * to ensure that if a record of this 'connector' table gets deleted, that it's associated
   * 'base' record also gets deleted.  This is a 2 step process that also relies on afterDelete().
   * See notes about this class's property '$justDeletedRecordArray above.
   * 
   * @param type $cascade 
   */
  function beforeDelete($cascade = true) {

    parent::beforeDelete($cascade);
    
    // Assume we the id of the record being deleted has been set by the call to delete()
    // so we can get to it via this->id
    //
    // Use that id to get the 'base' table id so we can delete the base table record (in afterDelete()).
  
    $this->justDeletedRecordArray = $this->find('first', array('conditions'=>array('ParamSirt.id'=>$this->id)));
    
    // must return true or the actual delete of this model's record will fail
    return true;
  } /////// end beforeDelete() ///////////
  
  
  
  /**
   * Cake callback.  I'm using it as a companion to 'beforeDelete()' to accomplish a single task
   * (see notes on beforeDelete()).
   */
  function afterDelete() {
    
    parent::afterDelete();
    
    $baseId = $this->justDeletedRecordArray['ParamSirt']['param_sirt_base_id'];
    
    //pr("In afterDelete(), this->justDeletedRecordArray['ParamFdk']['param_fdk_base_id']: ");
    //debug($this->justDeletedRecordArray);
    
    $deleted = $this->ParamSirtBasis->delete($baseId);   
    
  } ///////////// end afterDelete() ////////////////
  
  
  
} ///////////////// end class ////////////////////////////////////
